package com.cashmama.market.api.application.controller.message;

import com.cashmama.market.api.application.annos.VisitorAccessible;
import com.cashmama.market.api.application.controller.message.request.MessageListGetRequest;
import com.cashmama.market.api.application.controller.message.request.MessageReadPostRequest;
import com.cashmama.market.api.application.controller.message.response.MessageListInfoResponse;
import com.cashmama.market.api.application.controller.message.response.NotifyMessageResponse;
import com.cashmama.market.api.domain.enums.MessageTypeEnum;
import com.cashmama.market.api.domain.service.MessageService;
import com.cashmama.market.api.domain.vo.RequestLocalInfo;
import com.cashmama.market.api.domain.vo.message.MessageListInfoVO;
import com.cashmama.market.api.infras.handler.ApiResponse;
import com.cashmama.market.api.infras.handler.ResponseData;
import com.fqgj.common.api.annotations.ParamsValidate;
import com.fqgj.exception.common.ApiErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Objects;
import java.util.Optional;

/**
 * @program: market-api
 * @description 消息中心
 * @author: frank
 * @create: 2019-12-26 15:02
 **/
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 获取消息列表
     * @param messageListGetRequest
     * @return
     */
    @RequestMapping(value = "/list/get", method = RequestMethod.POST)
    @ParamsValidate
    @VisitorAccessible
    public ApiResponse<MessageListInfoResponse> list(@RequestBody @Valid MessageListGetRequest messageListGetRequest) {
//        String userCode = Optional.ofNullable(RequestLocalInfo.getCurrentUser().getUserCode())
//                .orElseThrow(() -> new ApiErrorException("userCode is null"));
//        Integer pageNo = Objects.isNull(messageListGetRequest.getPageNo()) ? 1 : messageListGetRequest.getPageNo();
//        MessageListInfoVO messageListInfoVO = messageService.getUserMessageList(userCode, pageNo, MessageTypeEnum.NOTICE.getType());
//        return new ApiResponse<>(new MessageListInfoResponse(messageListInfoVO)).setMsg("Query success");
        return new ApiResponse<>(new MessageListInfoResponse()).setMsg("Query success");
    }

    @RequestMapping(value = "/read", method = RequestMethod.POST)
    public ApiResponse<ResponseData> list(@RequestBody @Valid MessageReadPostRequest messageReadPostRequest) {

        return new ApiResponse<>("Query success");
    }

    @RequestMapping(value = "/notify/get", method = RequestMethod.POST)
    public ApiResponse<NotifyMessageResponse> notifylist() {

        return new ApiResponse<>(new NotifyMessageResponse()).setMsg("Query success");
    }

}
